//
//  ModifyCheckUserPasswordController.m
//  HuLaQuan
//
//  Created by hok on 1/21/16.
//  Copyright © 2016 Jianghao. All rights reserved.
//

#import "ModifyCheckUserPasswordController.h"

#import "ModifyUserPWFirstInputController.h"

#import "ModifyUserPasswordEngine.h"
@interface ModifyCheckUserPasswordController ()

@property (nonatomic, strong) ModifyUserPasswordEngine *modifyUserPWEngine;
@end

@implementation ModifyCheckUserPasswordController

- (ModifyUserPasswordEngine *)modifyUserPWEngine
{
    if (!_modifyUserPWEngine) {
        _modifyUserPWEngine = [[ModifyUserPasswordEngine alloc] init];
    }
    return _modifyUserPWEngine;
}

-(NSString *)finish:(NSString *)pwd{
    NSLog(@"haha %@",pwd);
    
    [self.passwordAndInfos setObject:pwd forKey:@"checkpassword"];
    
    [YuNetworkStatusUtilities showProgressMessage:NETWORK_LOADING];
    [self.modifyUserPWEngine verifyOldUserPassword:pwd];
   // [self performSegueWithIdentifier:@"ShowFirstInputPasswordViewControllerFromCheck" sender:self];
    return pwd;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Call Back
- (void)verifyPWForModifyPWFinish:(NSNotification*) notification
{
    //
    dispatch_async(dispatch_get_main_queue(), ^{
        [YuNetworkStatusUtilities dismissHUD];
    });
    NSDictionary *messageDic = [notification object];//获取到传递的对象
    if ([messageDic[@"isSuccess"] boolValue]) {
        [self performSegueWithIdentifier:@"ShowFirstInputPasswordViewControllerFromCheck" sender:self];
        
    }else{
        [self showNetWorkError:messageDic[@"message"]];
        
    }
}
#pragma mark - Life Cycle
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    
    // [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(verifyPWForModifyPWFinish:) name:@"VerifyPWForModifyUserPWFinish" object:nil];

}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"VerifyPWForModifyUserPWFinish" object:nil];

}
#pragma mark - Navigation


- (void)goBackAction
{
    UIAlertController *x = [UIAlertController alertWithTitle:@"提示" andMessage:@"是否放弃修改登录密码" andBlock:^(UIAlertAction *action ) {
        if ([action.title isEqualToString:@"好的"]) {
            
                [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
            
            [[UIApplication sharedApplication].keyWindow endEditing:YES];
        }
        
    }  type:@"confirmAndCancel"];
    [self presentViewController:x animated:YES completion:nil];
}

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([[segue identifier] isEqualToString:@"ShowFirstInputPasswordViewControllerFromCheck"]) {
        ModifyUserPWFirstInputController *controller = (ModifyUserPWFirstInputController*) [segue destinationViewController];
        
        controller.type = UserPassword;
        controller.titleOfNav = kReSetUserPasswordTitle;
        controller.titleOfPassword = kReSetUserPasswordHint;
        controller.passwordAndInfos = self.passwordAndInfos;
    }
}

@end
